#include "kxlib.h"

#include "net/netlib.h"

#include <luabind/luabind.hpp>

namespace {

const std::string GlobalLib = "__Kxlua_Global_Lib__";

}

namespace kxlua {

Kxlib::Kxlib(Lua& lua) : lua_(lua) {
    luabind::open(lua_.GetState());

    AddLib(new NetLib(lua_)); 
}

Kxlib::~Kxlib() {
    for (Libs::iterator it = libs_.begin(); it != libs_.end(); it++) {
        delete it->second;
    }
}

void Kxlib::AddLib(ILib* lib) {
    libs_.insert(std::make_pair(lib->GetName(), lib));
}

void Kxlib::RemoveLib(ILib* lib) {
}

ILib* Kxlib::GetLib(std::string lib) {
    Libs::iterator it = libs_.find(lib);
    if (it != libs_.end()) {
        return it->second;
    }
    return NULL;
}

}
